package serverside;

import java.sql.SQLException;

public class ATM {

    boolean userAuthenticated = false;
    Database myDatabase;
    String cardID = null;

    public ATM() {
        myDatabase = new Database();
    }

    public boolean isUserAuthenticated() {
        return userAuthenticated;
    }

    public void authenticateUser(String _CardID, String PIN) {
        //connect to database and check CardID and PIN         
        userAuthenticated = myDatabase.login(Integer.parseInt(_CardID), Integer.parseInt(PIN));
        cardID = _CardID;
    }

    public String fastCash(String amount) {
        return myDatabase.Withdraw(Integer.parseInt(cardID), Integer.parseInt(amount));
    }

    public String Transfer(String _accountNumber, String _amount) {
        String transactionResult = myDatabase.transfer(Integer.parseInt(_accountNumber),
                Integer.parseInt(_amount),
                Integer.parseInt(cardID));
        return transactionResult;
    }

    public String balanceInquiry() throws SQLException {
        return myDatabase.Balancing_query(Integer.parseInt(cardID));
    }

    public String payBill(String _companyName, String _Amount, String _billNumber, String _phoneNumber) throws SQLException
    {
        String str = myDatabase.bill_payment(Integer.parseInt(cardID), _companyName,
                Integer.parseInt(_Amount), Integer.parseInt(_billNumber), Integer.parseInt(_phoneNumber));
        return str;
    }

    public String Deposit(String _amount) {
        String str = myDatabase.Deposit(Integer.parseInt(cardID), Integer.parseInt(_amount));
        return str;

    }

}//end class atm
